#include"SeqList.h"
void SeqListInit(SL* ps)
{
	ps->a = NULL;
	ps->capacity = 0;
	ps->size = 0;
}
void SeqListPushFront(SL* ps)
{
	int x;
	scanf("%d", &x);
	SeqListChackCapacity(ps);
	int end = ps->size - 1;
	while (end >= 0)
	{
		ps->a[end + 1] = ps->a[end];
		end--;
	}
	ps->a[0] = x;
	ps->size++;
}
void SeqListChackCapacity(SL* ps)
{
	if (ps->size == ps->capacity)
	{
		int newcapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
		SQDataType* tep = (SQDataType*)realloc(ps->a, newcapacity * sizeof(SQDataType));
		if (tep == NULL)
		{
			printf("fail!");
			exit(-1);
		}
		else {
			ps->a = tep;
			ps->capacity = newcapacity;
		}
	}
}
void SeqListPrint(SL* ps)
{
	for (int i = 0; i < ps->size; i++)
	{
		printf("%d ", ps->a[i]);
	}
	printf("\n");
}
void SeqListBack(SL* ps)
{
	SeqListChackCapacity(ps);
	int x;
	scanf("%d", &x);
	ps->a[ps->size] = x;
	ps->size++;
}
void SeqListPop(SL* ps)
{
	int pos;
	scanf("%d", &pos);
	assert(pos <= ps->size);
	while (pos + 1 <= ps->size)
	{
		ps->a[pos-1] = ps->a[pos];
		pos++;
	}
	ps->size--;
}
void SeqListPush(SL* ps)
{
	SeqListChackCapacity(ps);
	int x,pos,t=ps->size;
	scanf("%d %d", &x,&pos);
	assert(pos <= ps->size);
	while (t >= pos)
	{
		ps->a[t] = ps->a[t - 1];
		t--;
	}
	ps->a[pos - 1] = x;
	ps->size++;
}